package com.three.productList.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.three.core.entity.Product;
import com.three.core.entity.ProductExamine;
import com.three.core.entity.User;
import com.three.core.vo.R;
import com.three.productList.dao.ProductExamineDao;
import com.three.productList.dao.ProductListDao;
import com.three.productList.feign.UserMyFeign;
import com.three.productList.service.ProductExamineService;
import com.three.productList.vo.ExaminePassVo;
import com.three.productList.vo.ExamineVo;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author ：li
 * @date ：Created in 2025/3/11 011 21:12
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class ProductExamineServiceImpl implements ProductExamineService {
    @Autowired
    private ProductExamineDao productExamineDao;
    @Autowired
    private ProductListDao productListDao;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private UserMyFeign userMyFeign;

    //查询
    @Override
    public R<IPage<ProductExamine>> select(ExamineVo examineVo) {
        Page<ProductExamine> page = new Page<>(examineVo.getCurrentPage(),examineVo.getPageSize());
        IPage<ProductExamine> productExamineIPage = productExamineDao.selectExamine(page, examineVo);
        return new R<>(200, "查询成功", productExamineIPage);
    }

    @Override
    public R<ProductExamine> updateExamine(ExaminePassVo form) {
        //获取当前登录者的信息
        String token=request.getHeader("token");
        String name = (String) redisTemplate.opsForHash().get("user::login::" + token, "name");
        R<User> userR = userMyFeign.selectByName(name);
        form.setUserId(userR.getData().getUserId());
        int row = productListDao.updateExamine(form);
        int update = productExamineDao.updateExamine(form);
        if (update == 1 && row == 1) {
            return new R<>(200, "审核成功", null);
        }
        return new R<>(400, "审核失败", null);
    }
}
